<template>
  <div class="announcement-carousel">
    <el-carousel
      :interval="autoplayInterval"
      :height="height"
      indicator-position="outside"
      @change="handleChange"
    >
      <el-carousel-item v-for="(item, index) in announcements" :key="index">
        <div class="announcement-item" @click="handleClick(item)">
<!--          <el-tag v-if="item.tag" :type="getTagType(item.noticeType)" size="small" class="announcement-tag">-->
<!--            {{ item.noticeType }}-->
<!--          </el-tag>-->
          <span class="announcement-title">{{ item.noticeTitle }}</span>
<!--          <span class="announcement-date">{{ item.date }}</span>-->
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  name: 'AnnouncementCarousel',
  props: {
    // 公告列表数据
    announcements: {
      type: Array,
      default: () => []
    },
    // 自动轮播间隔时间(ms)
    autoplayInterval: {
      type: Number,
      default: 10000
    },
    // 轮播高度
    height: {
      type: String,
      default: '60px'
    }
  },
  methods: {
    handleClick(item) {
      this.$emit('item-click', item)
    },
    handleChange(currentIndex, prevIndex) {
      // 可以在这里处理轮播切换事件
     // console.log(`从 ${prevIndex} 切换到 ${currentIndex}`)
    },
    getTagType(tag) {
      console.log("AAA",tag);
      // 根据标签内容返回不同的tag类型
      const tagTypes = {
        '1': 'warning',
        '2': 'info',
      }
      console.log(tagTypes[tag])
      return tagTypes[tag] || ''
    }
  }
}
</script>

<style scoped>
.announcement-carousel {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  overflow: hidden;
}

.announcement-item {
  display: flex;
  align-items: center;
  padding: 0 20px;
  height: 100%;
  background-color: #fff;
  cursor: pointer;
  transition: all 0.3s;
}

.announcement-item:hover {
  background-color: #f5f7fa;
}

.announcement-tag {
  margin-right: 10px;
  flex-shrink: 0;
}

.announcement-title {
  flex: 1;
  font-size: 14px;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.announcement-date {
  font-size: 12px;
  color: #909399;
  margin-left: 15px;
  flex-shrink: 0;
}



</style>
